<?
require("../../common/init.php");
require("author.php");
require("upfile.php");

$gee=$optional_field; // gee, 意为赶车时候喊的"驾", 此处用来表示次页面的主角对象
//$cate=$language; // cate = category, 分类
$cateid=0;

$title=ROOT_OPTIONAL_FIELD;
$url='optional_field';
$do=isset($_GET["do"])?clean($_GET["do"]):'view'; // 操作: 查看/编辑/删除 
$action=isset($_POST["action"])?clean($_POST["action"]):''; // 数据库操作: CURD 
$id=0; if (isset($_GET["id"])) $id = clean($_GET["id"]);
$page=1; if(isset($_GET["page"]))if(is_numeric($_GET["page"]))$page=$_GET["page"];

// sql action / sql 动作
switch ($action){
	case "update":
		//sql_update();
		break;
	case "add":
		sql_insert();
		break;
}

if($id==0){
	$order='id';
	$where=array();
	//if(ROOTUSERID!=$userid) {
	//	$where[]=array('name'=>'optional','val'=>1);
	//}
	$pages=$gee->count_pages($where);
	$info=$gee->get_page($page,$where,$order,"asc");
}
else $info=$gee->get_row($id);

function add()
{
	global $url;
	$row = array();
	echo '<form enctype="multipart/form-data" method="post" action="'.$url.'.php">';
	show_box($row, true, true);
	echo '<input type="hidden" name="action" value="add"></form>';
}

function flip($id)
{
	global $gee,$url, $page, $cateid;
	if($gee->flip($id)) echo "<script>location='$url-$cateid-p$page.html';</script>";
}
function delete($id)
{
	global $gee, $url, $page, $cateid;
	if($gee->delete($id))
	yell(ROOT_SUCCESS,"$url-$cateid-p$page.html");
}	
function show_info($info)
{
	global $id;
	if($id==0)
	{
  	show_boxes($info);
	}
	else 
	{
		show_box($info, false);
	}
}
function sql_insert()
{
	global $gee, $url, $page, $cateid;
	$arr=array(
		'table_name'=>$_POST["table_name"],
		'field_name'=>$_POST["field_name"],
	);
	if($gee->insert($arr))
	echo "<script>location='$url-$cateid-p$page.html';</script>";
}


// view 加载视图
require ROOTVIEW.$url.'.php';

// end of file